package com.chaofan.sell.dto;

import com.chaofan.sell.entity.OrderDetail;
import com.chaofan.sell.enums.OrderStatus;
import com.chaofan.sell.enums.PayStatus;
import com.chaofan.sell.utils.EnumUtil;
import com.chaofan.sell.utils.serializer.Date2LongSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单数据传输对象
 *
 * @author: Fairy
 * @date: 2021/9/7
 */
@Data
public class OrderDTO {
    /**
     * 订单id
     */
    private String orderId;

    /**
     * 买家名字
     */
    private String buyerName;

    /**
     * 买家电话
     */
    private String buyerPhone;

    /**
     * 买家地址
     */
    private String buyerAddress;

    /**
     * 买家openid
     */
    private String buyerOpenid;

    /**
     * 订单总金额
     */
    private BigDecimal orderAmount;

    /**
     * 订单状态，默认新订单，0
     */
    private Integer orderStatus;

    /**
     * 订单支付状态，默认未支付，0
     */
    private Integer payStatus;

    /**
     * 订单创建时间
     */
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date createTime;

    /**
     * 订单更新时间
     */
    @JsonSerialize(using = Date2LongSerializer.class)
    private Date updateTime;

    /**
     * 订单
     */
    private List<OrderDetail> orderDetailList;

    @JsonIgnore
    public OrderStatus getOrderStatus() {
        return EnumUtil.getByCode(orderStatus, OrderStatus.class);
    }

    @JsonIgnore
    public PayStatus getPayStatus() {
        return EnumUtil.getByCode(payStatus, PayStatus.class);
    }
}
